package top.bingoz.wanandroid.presenter

import top.bingoz.wanandroid.base.BasePresenter
import top.bingoz.wanandroid.bean.Data
import top.bingoz.wanandroid.contract.ArticleContract
import top.bingoz.wanandroid.data.http.observer.SimpleSubscriber
import top.bingoz.wanandroid.data.http.transformer.DataTransformer
import top.bingoz.wanandroid.model.ApiModel
import javax.inject.Inject

/**
 * @author su
 * @date 2018/7/30
 * @description
 */
class ArticlePresenter @Inject constructor(private val apiModel: ApiModel) : BasePresenter<ArticleContract.View>(), ArticleContract.Presenter {

    override fun getMainArticleList(page: Int) {

        apiModel.getMainArticleList(page)
                .compose<Data>(DataTransformer(bindToLifecycle()))
                .subscribe(object : SimpleSubscriber<Data>(mView) {
                    override fun onNext(data: Data) {
                        println(data.curPage)
                        mView?.showMainArticleList(data)
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                    }

                })

    }


    override fun destroy() {
    }
}